<?
include_once(INCLUDES."buildlink.php");
function rollback_menu($post)
{
$menuid=0;
$code=$post["code"];
	if($post["act"]=="baithi")
	{
		$post['code']="bai-thi";
		$q=query("select * from round where code='$post[round]'");
		$f=fetch($q);
		$post["roundname"]=$f["roundname"];
		$temp[]=array("title"=> "$post[roundname]","link" => buildlink("menu",$post));
		$menuid=0;
	}
	elseif($post["act"]=="oscar")
	{
		$post['code']="oscar-for-hair";
		$menuid=0;
	}
	elseif($post["act"]=="viewalbum")
	{
		$post["code"]="hinh-anh";
	}
	elseif($post["id"]!="")
	{
		if($post["act"]=="chitietbaithi")
		{
			$id=intval($post["id"]);
			$q=query("select * from baithi where id=$id");
			$f=fetch($q);
			$temp[]=array("title"=> $f["name"],"link" => buildlink("xembaithi",$f));
			$f["code"]="bai-thi";
			
			$q1=query("select * from round where id='$f[round]'");
			$f1=fetch($q1);
			$f["round"]=$f1["code"];
			$temp[]=array("title"=> "$f1[roundname]","link" => buildlink("menu",$f));
			$menuid=0;
		}
		else if($post["act"]=="post")
		{
			$id=intval($post["id"]);
			$q=query("select * from post where id=$id");
			$f=fetch($q);
			$temp[]=array("title"=> $f["name"],"link" => buildlink("post",$f));
			$menuid=$f["parent"];
		}
		else
		{
		}
	}
	if($post["code"]!="")
	{
		$q=query("select id from menu where code='$post[code]'");
		if(numrows($q))
		{
			$f=fetch($q);
			$menuid=$f["id"];
		}
	}
	while($menuid!=0)
	{
		$q=query("select * from menu where id=$menuid");
		if(numrows($q))
		{
			$f=fetch($q);
			$temp[]=array("title"=> $f["name"],"link" => buildlink("menu",$f));
			$menuid=$f["parent"];
		}
		else break;
	}
	
	$listmn[]=array("title" => "Trang Chủ", "link" => "./home.html");
	$n=count($temp);
	for($i=$n-1;$i>=0;$i--)
	{
		$listmn[]=$temp[$i];
	}
	return $listmn;
}